from django.db import models
from gxdm.models import Dwbmdm
from DataCenter.model.company import SoftwareCompany


class System(models.Model):
    id = models.AutoField(primary_key=True, verbose_name='编号')
    title = models.CharField(max_length=64, verbose_name='系统名称')
    alias = models.CharField(max_length=32, verbose_name='简称')
    ip = models.CharField(max_length=64, verbose_name='服务器公网IP', blank=True, null=True)
    inner_ip = models.CharField(max_length=64, verbose_name='服务器内网IP')
    domain = models.CharField(max_length=255, blank=True, null=True, verbose_name='域名')

    type_choice = (
        (1, '校内自建系统'),
        (2, '市属系统'),
        (3, '省属系统'),
        (4, '部属系统'),
    )

    type = models.IntegerField(choices=type_choice, verbose_name='类型')
    company = models.ForeignKey(SoftwareCompany, verbose_name='软件厂商', to_field='id', on_delete=models.PROTECT, db_column='company', blank=True, null=True)

    department = models.ForeignKey(Dwbmdm, verbose_name='管理部门', max_length=5, to_field='value',
                                   on_delete=models.PROTECT, db_column='department', blank=True, null=True)
    contact_person = models.CharField(max_length=64, blank=True, null=True, verbose_name='联系人学工号')
    is_use_cas = models.BooleanField(verbose_name='是否已对接中央认证')
    is_offer_data_interface = models.BooleanField('是否已提供数据接口')
    is_support_write_back = models.BooleanField('是否支持数据回写')
    remarks = models.TextField(max_length=255, blank=True, null=True, verbose_name='备注')
    create_time = models.DateTimeField("创建时间", auto_now_add=True)
    update_time = models.DateTimeField("更新时间", auto_now=True)

    class Meta:
        managed = False
        db_table = 'system'
        verbose_name = '系统'
        verbose_name_plural = '系统'

    def __str__(self):
        return self.title
